//
//  QLPublishView.m
//  神约
//
//  Created by qlwl on 17/2/8.
//  Copyright © 2017年 qlwl. All rights reserved.
//

#import "QLPublishPopView.h"

@implementation QLPublishPopView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
+(instancetype)getPublishView
{
    return [[[NSBundle mainBundle] loadNibNamed:@"QLPublishPopView" owner:self options:nil] lastObject];
}
- (void)showInView:(UIView *)superView
{
    [superView addSubview:self];
    self.frame = self.superview.bounds;
    self.alpha = 0;
    [UIView animateWithDuration:0.2 animations:^{
        self.alpha = 1;
    }];
}
- (void)remove
{
    [UIView animateWithDuration:0.2 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.frame = self.superview.bounds;
}

+(instancetype)showInWindow
{
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    QLPublishPopView * publishView = [self getPublishView];
    [publishView showInView:window];
    return publishView;
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    if ([touches isEqualToSet:[event touchesForView:self]]) {
        [self remove];
    }
}
- (IBAction)btn1Click:(id)sender {
    if (self.publishBtnClick) {
        self.publishBtnClick(1);
        [self remove];
    }
}
- (IBAction)btn2Click:(id)sender {
    if (self.publishBtnClick) {
        self.publishBtnClick(2);
        [self remove];
    }
}
- (IBAction)btn3Click:(id)sender {
    if (self.publishBtnClick) {
        self.publishBtnClick(3);
        [self remove];
    }
}



@end
